#ifndef DATABASEMANAGER_H
#define DATABASEMANAGER_H

#include <QObject>
#include <QtSql>
#include <iostream>
#include <QList>
#include "listeclient.h"
#include "objtosql.h"

#define q2c(string) string.toStdString()

class databaseManager
{

public:
    databaseManager();

//    enum TypeId {IDMYSQL = "SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT", IDSQLITE = "INTEGER PRIMARY KEY ASC"};

    enum TypeSql {MYSQL, SQLITE};

    void Connect(QString host, QString user ,QString pass, QString dbName, TypeSql typeSql);

    void OpenConnection();
    void CloseConnection();

    bool CreerTable(QString nom, QStringList typeData, QStringList NomChamp, QString foreignKey = "");
    QStringList ListeTable();
    void SupprimerTable(QString nom);

    void InsertValue(QStringList value, QStringList champ, QString table);
    void InsertValue(QString value, QString champ, QString table);
    int InsertValue(QStringList listeChampsSql, objToSQL *obj, QStringList sqlWhere, QString table);
    int InsertValue(Client client, QString table, QString tableContact, QString tableDateContact, QString tableDateObtenu);

    void RemoveValue(QString value, QString champ, QString table);
//    void RemoveValue(int id,  QString table, bool containsListe = false);
    void RemoveValue(QStringList where,  QString table, bool containsListe = false);

//    void UpdateValue(QString set, QString table, QString where);
    void UpdateValue(QString table, QString set, QStringList bindValues);

    QStringList GetValue(QString champ, QString table);
    QSqlQuery GetValueQuery(QStringList champs, QString table);

    int GetId(QString table, QStringList SQLWhere);

    static QString qMark(int count);

//signals:
//    void Message(QString message, int alignment = Qt::AlignBottom);

private:
    QSqlDatabase m_db;
    QString m_hostName;
    QString m_userName;
    QString m_password;
    QString m_databaseName;
    TypeSql m_TypeSql;
    QString m_typeId;

    bool m_connected;


};

#endif // DATABASEMANAGER_H
